package org.ianaz.chessfx.logic;

/**
 *
 * @author s.rainoldi
 */
public class Pawn extends Figure {

    public Pawn(Player player, Cell cell, int posX, int posY) {
        super(player, cell, posX, posY);
    }

    public boolean[][] getPossibleMoves() {
        int xone = getPosX();
        int yone = getPosY() + (1 * getPlayer().getMultiplier());
        allowedMoves[xone][yone] = true;

        // It's the first move? Then you'll be allowed to move two cells instead of one
        if (getMoves() == 0) {
            allowedMoves[getPosX()][getPosY() + (2 * getPlayer().getMultiplier())] = true;
        }
        try {
            // Is there an enemy pawn? Then you'll be allowed to move diagonal by one point
            Cell[][] cells = getCell().getGame().getCells();
            if (cells[xone + 1][yone + (1 * getPlayer().getMultiplier())].getFigure() != null) {
                // I found an enemy on one point diagonal left/right, I can eat it!
                allowedMoves[xone + 1][yone] = true;
            }
            if (cells[xone - 1][yone + (1 * getPlayer().getMultiplier())].getFigure() != null) {
                // I found an enemy on one point diagonal left/right, I can eat it!
                allowedMoves[xone - 1][yone] = true;
            }
        } catch (Exception e) {
            // Is going out of the board
        }

        for (int i = 0; i < allowedMoves.length; i++) {
            for (int l = 0; l < allowedMoves[i].length; l++) {
                if (allowedMoves[i][l] == true) {
                    System.out.println("Cella: " + i + " " + l);
                }
            }
        }

        return allowedMoves;
    }
}